package com.cug.campus_sh_market_server.controller;

import com.cug.campus_sh_market_server.config.aop.ValidateAspect;
import com.cug.campus_sh_market_server.entity.param.OrderParam;
import com.cug.campus_sh_market_server.entity.param.PageParam;
import com.cug.campus_sh_market_server.entity.po.BaseEntity;
import com.cug.campus_sh_market_server.entity.vo.ResultData;
import com.cug.campus_sh_market_server.service.IRestfullService;
import com.nycreativity.elecreativity.entity.vo.PageDataVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author sxt
 * @version 1.0
 * @description TODO
 * @date 2022/3/29 22:56
 */
@PreAuthorize("isAuthenticated()")
public abstract class AbsPreAuthorizeRestfullController
        <Entity extends BaseEntity, GetParam extends BaseEntity, AddParam extends BaseEntity, PutParam extends BaseEntity, VO extends BaseEntity>
        extends AbsRestfullController<Entity, GetParam, AddParam, PutParam, VO> {


    @PostMapping
    @ValidateAspect.ParamValidate
    @ApiOperation("添加数据")
    protected ResultData<VO> addData(@RequestBody @Valid AddParam addParam, BindingResult result) {
        return super.addData(addParam, result);
    }

    protected ResultData<Boolean> removeData(Integer id) {
        return super.removeData(id);
    }


    @PutMapping
    @ValidateAspect.ParamValidate
    @ApiOperation("修改数据")
    protected ResultData<Boolean> putData(@RequestBody @Valid PutParam putParam, BindingResult result) {
        return super.putData(putParam, result);
    }

    @GetMapping
    @ApiOperation("查询数据")
    protected ResultData<List<VO>> getData(GetParam getParam, OrderParam orderParam) {
        return super.getData(getParam, orderParam);
    }

    @GetMapping("/page")
    @ApiOperation("查询数据(带分页)")
    protected ResultData<PageDataVO<VO>> getDataByPage(GetParam getParam, PageParam pageParam, OrderParam orderParam) {
        return super.getDataByPage(getParam, pageParam, orderParam);
    }

}
